package work.parabola.keyboardswitch.pojo.query.plate;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import work.parabola.keyboardswitch.common.ResponseCode;
import work.parabola.keyboardswitch.common.ServerResponse;

@Data
@ToString
@EqualsAndHashCode
public class AddTesterQuery {

    private Integer row;

    private Integer col;

    private String name;

    private Boolean open;

    ServerResponse validate() {
        if (this.row == null || this.col == null || this.open == null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),
                    ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        if(StringUtils.isBlank(this.name)){
            return ServerResponse.createByErrorMessage("试轴器名称不能为空");
        }
        if(row.compareTo(0) <= 0){
            return ServerResponse.createByErrorMessage("试轴器行数不能小于0");
        }
        if(this.col.compareTo(0) <= 0){
            return ServerResponse.createByErrorMessage("试轴器列数不能小于0");
        }
        return ServerResponse.createBySuccess();
    }
}
